//企业简历详情基本信息
import React, {Component} from 'react'
import {ScrollView, Text, TouchableOpacity, View,} from 'react-native';

import {Cresumebutton_Style as styles} from '../../../../styles';
import Modal from 'react-native-modal';
import Autoinput3 from '../../../util/inputUtil3';
import {getSize} from '../../../util/sizeUtil'
import Timeutil from '../../../util/newtimeUtil';
import Timeutil2 from '../../../util/timepickerUtil';
import {PostionSendAcceptAction,} from "../../../actions/postion_c";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
import {fetchRequest} from "../../../util/fetch";

let Dimensions = require('Dimensions');
let width = Dimensions.get('window').width;

class Cresume_button1 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            time: new Date(),
            msg: '',
            isModalVisible: false,
            companyName: '',
            companyLocation: ''
        };
    }

    //加载后渲染页面
    componentDidMount() {
        let postionId = this.props.navigation.state.params.postionId;
        fetchRequest('CompanyInfo/selectCompanyNameAndLocation.go', 'POST', {postionId: postionId}).then(
            res => this.setState({
                companyName: res.companyName,
                companyLocation: res.companyLocation
            })
        );
    }

    _showModal = () => this.setState({isModalVisible: true});
    _hideModal = () => this.setState({isModalVisible: false});

    render() {
        return (
            <View>
                <TouchableOpacity activeOpacity={1} onPress={this._showModal}
                                  style={[styles.but_in, {width: width * 0.42}]}>
                    <Text style={styles.but_text}>
                        预约面试
                    </Text>
                </TouchableOpacity>


                <Modal isVisible={this.state.isModalVisible}
                       animationIn={'slideInLeft'}
                       animationOut={'slideOutRight'}>
                    <View style={styles.skill_modal}>
                        <Text style={styles.skill_text}>预约面试信息</Text>
                        <Text style={styles.but_text4}>公司名称：
                            <Text style={styles.but_pos}>{this.state.companyName}</Text>
                        </Text>
                        <View style={styles.but_textout}>
                            <Text style={styles.but_text1}>面试地点：</Text>
                            <ScrollView style={styles.rout} ref="sv2">
                                <View style={styles.but_textout2} ref="v2">
                                    <Autoinput3
                                        text={this.state.companyLocation}
                                        style={[styles.inputname, {width: width * 0.7}]}
                                        function={this.setLocation.bind(this)}
                                        onChange={this.gooo.bind(this)}
                                        onFocus={this.gooo.bind(this)}
                                    />
                                </View>
                            </ScrollView>

                        </View>
                        <View style={styles.but_textout3}>
                            <Text style={styles.but_text1}>
                                时&emsp;&emsp;间：
                            </Text>
                            <View style={styles.text_timea}>
                                <View style={styles.border}>
                                    <Timeutil
                                        function={this.setTime0.bind(this)}
                                        onChange={this.gooo.bind(this)}
                                        onFocus={this.gooo.bind(this)}
                                        time={this.state.time}
                                    />
                                </View>
                                <Text>&emsp;</Text>
                                <View style={styles.border}>
                                    <Timeutil2
                                        function={this.setTime1.bind(this)}
                                        onChange={this.gooo.bind(this)}
                                        onFocus={this.gooo.bind(this)}
                                        time={this.state.time}
                                    />
                                </View>
                            </View>
                        </View>

                        <ScrollView style={styles.rout} ref="sv">
                            <View style={styles.but_textout2} ref="v1">
                                <Text style={styles.but_text1}>附加信息：</Text>
                                <View style={[styles.border2, {width: width * 0.7}]}>
                                    <Autoinput3
                                        style={[styles.inputname,]}
                                        function={this.setMsg.bind(this)}
                                        onChange={this.gooo.bind(this)}
                                        onFocus={this.gooo.bind(this)}/>
                                </View>
                            </View>
                        </ScrollView>

                        <View style={styles.skill_yesno}>
                            <TouchableOpacity style={styles.skill_yesout}>
                                <Text onPress={() => this.commit()} style={styles.skill_yes}>确定</Text>
                            </TouchableOpacity>
                            <TouchableOpacity style={styles.skill_noout}>
                                <Text onPress={this._hideModal} style={styles.skill_no}>取消</Text>
                            </TouchableOpacity>
                        </View>

                    </View>
                </Modal>
            </View>
        )
    }

    commit() {
        const {actions} = this.props;
        actions.PostionSendAcceptAction({
            sendId: this.props.sendId,
            postionId: this.props.postionId,
            location: this.state.companyLocation,
            msg: this.state.msg,
            time: this.state.time.getTime(),
            companyName: this.state.companyName
        });
        this._hideModal();
        this.props.navigation.goBack();
    }

    setLocation(companyLocation) {
        this.setState({companyLocation: companyLocation});
    }

    setTime0(time) {
        let thisTime = this.state.time;
        thisTime.setFullYear(time.getFullYear());
        thisTime.setMonth(time.getMonth());
        thisTime.setDate(time.getDate());
        this.setState({time0: thisTime});
    }

    setTime1(time) {
        let thisTime = this.state.time;
        thisTime.setHours(time.getHours());
        thisTime.setMinutes(time.getMinutes());
        this.setState({time0: thisTime});
    }

    setMsg(msg) {
        this.setState({msg: msg});
    }

    gooo() {
        getSize(this.refs.v1).then(res => {
            this.refs.sv.scrollTo({x: 0, y: (res.height + res.pageY), animated: true})
        })
    }
}

//20171221-王继顺
//组合action
let actions = {
    PostionSendAcceptAction,
};
//连接state到props
const mapStateToProps = state => {
    return {
        Reducer: state.PostionSendAcceptReducer //自己的reducers
    }
};
//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
};
//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(Cresume_button1);